// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    {                                         \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    }
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;
const int N = 1e5 + 50;

int t, n;

int cnt[N][26];

char s[N];

int cnt2[N][26];

int findmax(int a[26]) {
    int res = a[0];
    for (int i = 1; i < 26; ++i)
        res = max(res, a[i]);
    return res;
}

vector<int> pos[26];
int mx[N];
int main(int argc, char const *argv[]) {
    // code
    scanf("%s", s);
    n = strlen(s);
    cnt[0][s[0] - 'a'] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 26; ++j)
            cnt[i][j] = cnt[i - 1][j] + (j == s[i] - 'a');
    }
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j)
            cnt2[i][j] = cnt2[i + 1][j] + (j == s[i] - 'a');
        mx[i] = findmax(cnt2[i]);
    }
    LL ans = 0;
    for (int i = 0; i < n; ++i)
        pos[s[i] - 'a'].push_back(i);
    for (int i = 0; i < 26; ++i) {
        ans = max(ans, (LL)cnt[n - 1][i]);

        for (int j = 0; j < 26; ++j) {
            LL tans = 0;
            for (int p : pos[i])
                tans += cnt2[p + 1][j];
            ans = max(ans, tans);
            // dbg(i, j, ans);
        }
    }
    printf("%lld\n", ans);
    return 0;
}
